local mubing = fk.CreateSkill {

  name = "joy__mubing",

  tags = {  },

}



mubing:addEffect("active", {
  name = "joy__mubing",
  anim_type = "drawcard",
  prompt = "展示牌堆顶四张牌，然后你弃置任意张手牌，获得其中点数和不小于弃置牌点数和的牌",
  can_use = function(self, player)
    return player:usedSkillTimes(mubing.name, Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local cards = room:getNCards(4)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
    })
    local can_throw = table.filter(player:getCardIds("h"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    if #can_throw > 0 then
      local result = room:askForPoxi(player, "joy__mubing_prey", {
        { "joy__mubing_to_prey", cards },
        { "joy__mubing_to_throw", can_throw },
      }, nil, true)
      local get, throw = {}, {}
      for _, id in ipairs(result) do
        if table.contains(cards, id) then
          table.insert(get, id)
        else
          table.insert(throw, id)
        end
      end
      if #throw > 0 then
        room:throwCard(throw, mubing.name, player, player)
      end
      if #get > 0 and not player.dead then
        local dummy = Fk:cloneCard("dilu")
        dummy:addSubcards(get)
        room:obtainCard(player, dummy, true, fk.ReasonPrey)
        for _, id in ipairs(get) do
          local card = Fk:getCardById(id)
          room:setCardMark(card,"@@joy__mubing-inhand",1)
        end
      end
    end
  end,
})

return mubing